package ch11;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

class _21_TreeMapEx {
	public static void main(String[] args) {
		String[] data = { "A", "K", "A", "K", "D", "K", "A", "K", "K", "K",	"Z", "D" };

		Map<String,Integer> map = new TreeMap<String,Integer>();
		for (int i = 0; i < data.length; i++) {
			if (map.containsKey(data[i])) map.put(data[i], map.get(data[i])+1);
			else map.put(data[i],1);
		}

		Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
		for(Map.Entry<String,Integer> entry:entrySet)
			System.out.println(entry.getKey() + ": " + printBar('#', entry.getValue()) + " " + entry.getValue());
	}	

	public static String printBar(char ch, int value) {
		char[] bar = new char[value];
		for (int i = 0; i < bar.length; i++) bar[i] = ch;
		return new String(bar);
	}
}
	
/*
A: ### 3
D: ## 2
K: ###### 6
Z: # 1
*/	